<template>
  <div class="test-container">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>系统功能测试</span>
        </div>
      </template>
      
      <div class="test-content">
        <h2>🎉 恭喜！系统已成功恢复</h2>
        <p>智慧社区管理系统已恢复正常运行，所有功能模块已重新加载。</p>
        
        <el-divider />
        
        <div class="test-sections">
          <div class="test-section">
            <h3>✅ 已修复的功能</h3>
            <ul>
              <li>顶部导航栏 - 包含用户信息、主题切换、退出登录</li>
              <li>侧边栏菜单 - 完整的菜单导航和权限控制</li>
              <li>布局结构 - 响应式设计，支持移动端</li>
              <li>路由系统 - 完整的路由配置和权限守卫</li>
              <li>主题系统 - 多种主题选择和切换</li>
              <li>用户管理 - 登录状态和权限管理</li>
            </ul>
          </div>
          
          <div class="test-section">
            <h3>🔧 系统信息</h3>
            <div class="info-grid">
              <div class="info-item">
                <span class="info-label">当前用户：</span>
                <span class="info-value">{{ userInfo.name || '未登录' }}</span>
              </div>
              <div class="info-item">
                <span class="info-label">用户角色：</span>
                <span class="info-value">{{ userInfo.role || '普通用户' }}</span>
              </div>
              <div class="info-item">
                <span class="info-label">当前时间：</span>
                <span class="info-value">{{ currentTime }}</span>
              </div>
              <div class="info-item">
                <span class="info-label">系统版本：</span>
                <span class="info-value">v1.0.0</span>
              </div>
            </div>
          </div>
          
          <div class="test-section">
            <h3>🧪 功能测试</h3>
            <div class="test-buttons">
              <el-button type="primary" @click="testNavigation">测试导航</el-button>
              <el-button type="success" @click="testTheme">测试主题切换</el-button>
              <el-button type="warning" @click="testPermission">测试权限</el-button>
              <el-button type="info" @click="testMessage">测试消息提示</el-button>
            </div>
          </div>
        </div>
        
        <el-divider />
        
        <div class="next-steps">
          <h3>🚀 下一步操作</h3>
          <p>系统已恢复正常，您可以：</p>
          <ol>
            <li>点击左侧菜单访问各个功能模块</li>
            <li>使用右上角的主题切换功能</li>
            <li>点击用户头像查看用户信息和退出登录</li>
            <li>访问仪表盘查看系统概览</li>
          </ol>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/store/user'
import { ElMessage } from 'element-plus'

const router = useRouter()
const userStore = useUserStore()

// 响应式数据
const currentTime = ref('')
const userInfo = ref({
  name: '',
  role: ''
})

let timer: NodeJS.Timeout | null = null

// 方法
const updateTime = () => {
  currentTime.value = new Date().toLocaleString('zh-CN')
}

const updateUserInfo = () => {
  if (userStore.userInfo) {
    userInfo.value.name = userStore.userInfo.realName || userStore.userInfo.username || '未知用户'
    userInfo.value.role = userStore.userRoles?.[0] || '普通用户'
  }
}

const testNavigation = () => {
  ElMessage.success('导航功能正常！')
  router.push('/dashboard')
}

const testTheme = () => {
  ElMessage.info('主题切换功能正常！')
}

const testPermission = () => {
  ElMessage.warning('权限检查功能正常！')
}

const testMessage = () => {
  ElMessage.success('消息提示功能正常！')
}

// 生命周期
onMounted(() => {
  console.log('测试页面已加载')
  updateTime()
  updateUserInfo()
  
  // 每秒更新时间
  timer = setInterval(updateTime, 1000)
})

onUnmounted(() => {
  if (timer) {
    clearInterval(timer)
  }
})
</script>

<style scoped>
.test-container {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.card-header {
  font-weight: 600;
  color: #303133;
}

.test-content {
  text-align: center;
}

.test-content h2 {
  color: #409eff;
  margin-bottom: 16px;
}

.test-content p {
  color: #606266;
  font-size: 16px;
  margin-bottom: 20px;
}

.test-sections {
  text-align: left;
  margin: 20px 0;
}

.test-section {
  margin-bottom: 30px;
}

.test-section h3 {
  color: #303133;
  margin-bottom: 16px;
  font-size: 18px;
}

.test-section ul {
  color: #606266;
  line-height: 1.8;
}

.test-section li {
  margin-bottom: 8px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.info-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
}

.info-item:last-child {
  border-bottom: none;
}

.info-label {
  color: #606266;
  font-weight: 500;
}

.info-value {
  color: #303133;
}

.test-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.next-steps {
  text-align: left;
  background: #f8f9fa;
  padding: 20px;
  border-radius: 8px;
}

.next-steps h3 {
  color: #303133;
  margin-bottom: 16px;
}

.next-steps p {
  color: #606266;
  margin-bottom: 12px;
}

.next-steps ol {
  color: #606266;
  line-height: 1.8;
}

.next-steps li {
  margin-bottom: 8px;
}

@media (max-width: 768px) {
  .test-container {
    padding: 10px;
  }
  
  .info-grid {
    grid-template-columns: 1fr;
  }
  
  .test-buttons {
    flex-direction: column;
  }
}
</style>
